﻿Imports ajayumi.develop.win32.WebResourcesCatcher.Components
Imports ajayumi.develop.win32.WebResourcesCatcher.Service
Imports System.Text


Public Class DlgNewTask

    Private m_ResTaskInfo As ResTaskInfo = Nothing
    Public ReadOnly Property ResTaskInfo() As ResTaskInfo
        Get
            Return m_ResTaskInfo
        End Get
    End Property


    Protected Overrides Sub btnSubmit_Click(sender As Object, e As System.EventArgs)
        Me.m_ResTaskInfo = New ResTaskInfo() With { _
            .SiteUrl = Me.txtSiteUrl.Text.Trim(), _
            .SaveDir = Me.txtSaveDir.Text.Trim(), _
            .IsAutoDownload = Me.chkAutoDownload.Checked, _
            .IsTraversal = Me.chkTraversal.Checked, _
            .ImgWidthLB = Me.nudWidth.Value, _
            .ImgHeightLB = Me.nudHeight.Value, _
            .MatchMode = IIf(Me.chkAnd.Checked, MatchMode.AND, MatchMode.OR), _
            .HtmlEncode = DirectCast(Me.cboEncode.SelectedItem, EncodeInfo).Encode}

        If Not Me.m_ResTaskInfo.SaveDir.EndsWith("\") Then
            Me.m_ResTaskInfo.SaveDir = String.Concat(Me.m_ResTaskInfo.SaveDir, "\")
        End If

        MyBase.btnSubmit_Click(sender, e)
    End Sub

    Private Sub btnSelectDir_Click(sender As System.Object, e As System.EventArgs) Handles btnSelectDir.Click
        Using dlg As New FolderBrowserDialog()
            If dlg.ShowDialog() = DialogResult.OK Then
                Me.txtSaveDir.Text = dlg.SelectedPath
            End If
        End Using
    End Sub

    Private Sub DlgNewTask_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.txtSiteUrl.Text = "http://www.huaban.com/"
        Me.txtSaveDir.Text = "E:\Temp\huaban"

        Me.bindEncode()
    End Sub

    Private Sub bindEncode()
        Dim _List As New List(Of EncodeInfo)()
        With _List
            .Add(New EncodeInfo() With {.Name = "Default", .Encode = Encoding.Default})
            .Add(New EncodeInfo() With {.Name = "GB2312", .Encode = Encoding.GetEncoding("GB2312")})
            .Add(New EncodeInfo() With {.Name = "UTF8", .Encode = Encoding.UTF8})
        End With
        Me.cboEncode.DisplayMember = "Name"
        Me.cboEncode.ValueMember = "Encode"
        Me.cboEncode.DataSource = _List
    End Sub

    Private Sub btnOpenCodeDlg_Click(sender As System.Object, e As System.EventArgs) Handles btnOpenCodeDlg.Click
        Dim _Url As String = Me.txtSiteUrl.Text.Trim()
        If Not String.IsNullOrEmpty(_Url) Then
            Using frm As New frmHtmlCode()
                frm.SetDefaultUrl(_Url)
                frm.ShowDialog()
            End Using
        Else
            MsgBox("请输入网站地址")
        End If
    End Sub


End Class

